#ifndef _XML_UTIL_H
#define _XML_UTIL_H
#include <header.h>


/*configure file field marco*/
#define CONF_ELEM	"config"

#define PROGRAM_ELEM	"program"
#define USER_DEFINED_ELEM	"user-defined"
#define MISC_ELEM	"misc"

#define ITEM_ELEM	"item"
#define IS_FIRST_TIME_ELEM	"isfirsttime"
#define START_WITH_BOOT_ELEM	"startwithboot"
#define COUNTER_ATTR	"counter"
#define SEQNUM_ATTR	"seqnum"
#define PATH_ATTR	"path"
#define ALLOW_ATTR	"allow"

#define MD5DIGEST_ATTR "md5digest"
/*user-defined elem attr*/
#define DESC_ATTR	"description"
#define PROTO_ATTR	"protocol"
#define LPF_ATTR	"localport-from"
#define LPT_ATTR	"localport-to"
#define RPF_ATTR	"remoteport-from"
#define RPT_ATTR	"remoteport-to"
#define ACTION_ATTR	"action"
#define STATUS_ATTR	"active"

#define DEFAULT_COUNTER_VALUE 0
#define YES_VALUE	"yes"
#define NO_VALUE	"no"
#define TCP_VALUE	"tcp"
#define UDP_VALUE	"udp"
#define ACCEPT_VALUE	"accept" 
#define DROP_VALUE	"drop" 

#define PATH(x)		(const xmlChar *)"//"x

#define MD5SUM_LEN 128/4

struct program_item
{
  struct list_head list;
  char *path;
  int allow;/*1--allow, 0--deny*/
};
struct user_defined_item
{
  struct list_head list;
  char *desc;
  int proto;/*tcp or udp*/
  int localport_from;
  int localport_to;
  int remoteport_from;
  int remoteport_to;
  int action;/*ACCEPT or DROP*/
  int status;/*1--active 0--not active*/
};
void init_conf_xml(void);
int is_first_time_start(void);
void set_program_have_started(void);
int xml_allow_program(xmlChar *path);
int xml_deny_program(xmlChar *path);
void xml_del_program_item(xmlChar *path);
int xml_is_allow_program(xmlChar *path);
struct list_head *get_program_list(void);
void free_program_list(struct list_head *service_head);
int xml_updatemd5_program(xmlChar * path);
void xml_add_user_defined_rules(xmlChar *rules_desc,
                                int proto,
                                int localport_from,
                                int localport_to,
                                int remoteport_from,
                                int remoteport_to,
                                int action);
void xml_delete_user_defined_rules(xmlChar *rule_desc);
void xml_set_user_defined_rules_status(xmlChar *rules_desc, xmlChar *active);
#endif
